home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / EXPENSE2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  1.5 KB  |  56 lines

  1. // expense2.cpp -- The object-oriented version of the travel
  2. // expense program
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. class Expense {             // The trip expense object type
  7. public:
  8.   char TripName[80], Date[80];
  9.   int Mileage, Cost, Fringe;
  10.   void AskQuestions(void);
  11.   void CheckWithBoss(void);
  12. };
  13.  
  14. Expense ExRec[20];
  15. int ExCount, I;
  16.  
  17. void Expense::AskQuestions(void)
  18. // This function gathers data for the expense object
  19. {
  20.   printf("Please enter the name of your trip: ");
  21.   scanf("%s", TripName);
  22.   printf("Which date did you leave (mo/day/year)? ");
  23.   scanf("%s", Date);
  24.   printf("Enter the number of miles for your trip: ");
  25.   scanf("%d", &Mileage);
  26.   printf("Enter the cost of your trip: ");
  27.   scanf("%d", &Cost);
  28.   printf("Enter the cost of your meals and entertainment: ");
  29.   scanf("%d", &Fringe);
  30. }
  31.  
  32. void Expense::CheckWithBoss(void)
  33. // The boss is very tough. He won't approve every trip.
  34. {
  35.   if (!stricmp(TripName,"Hawaii") || !stricmp(TripName,"Tahiti"))
  36.     printf("%s: You are fired for trying to sneak this one by\n",
  37.            TripName);
  38.   else if (Cost/4 < Fringe)
  39.     printf("The fringe expenses for the %s trip are too high\n",
  40.            TripName);
  41.   else
  42.     printf("The %s trip is ok\n", TripName);
  43. }
  44.  
  45. int main(int, char *)
  46. {
  47.   printf("How many trips did you take? ");
  48.   scanf("%d", &ExCount);
  49.   for (I=0; I<ExCount; I++)   // Get expense data for each employee
  50.     ExRec[I].AskQuestions();
  51.   for (I=0; I<ExCount; I++)   // Write out the boss's response
  52.     ExRec[I].CheckWithBoss();
  53.   return 0;
  54. }
  55.  
  56.